package com.kgc.controller;

import com.kgc.entity.TbContent;
import com.kgc.service.FindAllSolrService;
import com.kgc.service.TbContentService;
import com.kgc.utils.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("tb")
public class TbController {
    @Autowired
    private TbContentService  tbContentService;
    @Autowired
    private FindAllSolrService findAllSolrService;
    @RequestMapping("list")
    @ResponseBody
    public ResultTable findAll(
            @RequestParam(value = "page",required = false,defaultValue = "1")int   page,
            @RequestParam(value = "pageSize",required = false,defaultValue = "3")int   pageSize){
        ResultTable rs = tbContentService.findAll(page, pageSize);
        return rs;
    }

    @RequestMapping("content/add")
    @ResponseBody
    public Map add(TbContent tbContent){
        HashMap<Object, Object> map = new HashMap<>();
        tbContent.setUpdated(new Date());
        tbContent.setCreated(new Date());
        map.put("msg","添加成功");
        return map;
    }
    @RequestMapping("item/addSolr")
    @ResponseBody
    public void addSolr(Model model){
        model.addAttribute("code",0);
        model.addAttribute("status",200);
        model.addAttribute("msg",findAllSolrService.findAllSolr());
}
}
